import Koa from 'koa'
import KoaRouter from 'koa-router'
import allRouterLoader from './common/AllRouterLoader'
import globalExceptionMid from '@/middleware/globalExceptionMid'
import respUtilMid from './middleware/respUtilMid'
import logUtil from './utils/logUtil'

async function bootstrap() {
  const app = new Koa()
  const router = new KoaRouter()

  // 注册返回方法
  app.use(respUtilMid)
  // 注册全局错误处理
  app.use(globalExceptionMid)
  // 注册所有路由
  await allRouterLoader.init(app, router, '/dang')

  app.listen(3502)
  logUtil.info('server running on port 3502')
}

bootstrap()
